package gp;
/**
 * A Tree Node
 * @author silviojr
 *
 */
public class Node{
	public Symbol symbol;
	public Node parent;
	public Node left;
	public Node right;

	public Node(Node parent){
		this.symbol = null;
		this.parent = parent;
		this.left = this.right = null;
	}
	public Node(Symbol symbol, Node parent){
		this.symbol = symbol;
		this.parent = parent;
		this.left = this.right = null;
	}
	
	public boolean has_left(){
		return (this.left != null);
	}
	
	public boolean has_right(){
		return (this.right != null);
	}

	public boolean is_root(){
		return(this.parent == null);
	}

	public boolean is_leaf(){
		return(this.left == null && this.right == null);
	}

	public int height(){
		if(this.is_leaf()){
			return 1;
		}
		int height_left = 0;
		int height_right = 0;
		if(this.left != null){
			height_left = this.left.height();
		}
		if(this.right != null){
			height_right = this.right.height();
		}
		return Math.max(height_right, height_left) + 1;
	}
}